import Vue from 'vue';
import Router from 'vue-router';
import store from '../store/index';

let routerMode = 'history';
Vue.use(Router);

const routes = [
  {path: '/', redirect: '/desktop'},
  {
    path: '/desktop', name: 'pc桌面', meta: {
      title: '欢迎',
      requireAuth: false
    }, props: true, component: () => import('@/page/system/winDesktop')
  },
  {
    path: '/login', name: '登陆', meta: {
      title: '登陆',
      requireAuth: false
    }, props: true, component: () => import('@/page/user/login')
  },
];

const router = new Router({mode: routerMode, routes: routes});

router.beforeEach((to, from, next) => {
  let userinfo = store.getters.user || null
  if (to.matched.some(r => r.meta.requireAuth)) {
    if (userinfo) {
      if (to.path === "/desktop") {
        next()
      } else {
        next();
      }

    } else {
      next({
        path: '/login'
      })
    }
  } else {
    next();
  }

});
// 自定义
const appPages = {
  drawbox: () => () => import('@/page/Apps/drawbox/main'),
};
router.appPages = appPages;
export default router;
